package com.bawei.module_sign.ui

import com.bawei.lib_common.base.BaseViewModel
import com.bawei.lib_common.base.state.Failed
import com.bawei.lib_common.base.state.Loading
import com.bawei.lib_common.base.state.RequestEvent
import com.bawei.lib_common.base.state.Success
import com.bawei.module_sign.model.ClockModel
import com.bawei.module_sign.model.SignModelItem
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import javax.inject.Inject


@HiltViewModel
class SignViewModel @Inject constructor(private val repository: SignRepository) : BaseViewModel() {

    var mSignListData = listOf<SignModelItem>()

    val mSign_ = MutableStateFlow<RequestEvent>(Loading)

    val mSignState = mSign_.asStateFlow()

    fun getSign(userId : Int) {
        execute(
            action = repository.getSign(userId),
            onStart = {
                mSign_.value = Loading
            },
            onError = {
                mSign_.value = Failed(it)
            },
            onFinish = {
                mSignListData = it.data
                mSign_.value = Success
            }
        )
    }

    var mClockListData = listOf<ClockModel>()
    val mClock_ = MutableStateFlow<RequestEvent>(Loading)
    val mClockState = mClock_.asStateFlow()

    fun getClock(clockModel: ClockModel) {
        execute(
            action = repository.getClock(clockModel),
            onStart = {
                mClock_.value = Loading
            },
            onError = {
                mClock_.value = Failed(it)
            },
            onFinish = {
                mClockListData = listOf(it.data)
                mClock_.value = Success
            }
        )
    }


}